/**
 * Constants and initialization function for the 'login' page
 * @const
 */
webapp.login = (function(){
	Ext.require('Ext.form.Panel');
	Ext.require('Ext.form.field.Checkbox');

	return {
		IDS: {
			/**
			 * Action URL - the URL to which the form has to transfer data
			 *  when a user performs authorization. This is a std. Spring security
			 *  validation page and it must not be changed.
			 *
			 * @const
			 */
			ACTION_URL: 'j_spring_security_check',

			/**
			 * The name of the field of user's login.
			 * @const
			 */
			FIELD_LOGIN: {
				/**@const */
				NAME: 'j_username',

				/**@const */
				LABEL: webapp.LOCALE.LOGIN
			},

			/**
			 * The name of the field of user's password.
			 * @const
			 */
			FIELD_PASSWORD: {
				/** @const */
				NAME: 'j_password',

				/** @const */
				LABEL: webapp.LOCALE.PASSWORD
			},

			/**
			 * The name of the field 'Remember me'.
			 * @const
			 */
			FIELD_REMEMBER_ME: {
				/** @const */
				NAME: '_spring_security_remember_me',

				/** @const */
				LABEL: webapp.LOCALE.REMEMBER_ME
			}
		},

		/**
		 * Login initialization function that is called when a web page is completly loaded.
		 * @const
		 */
		init: function() {
			Ext.create('Ext.Window', {
				width: 300,
				height: 135,

				border: false,
				closable: false,
				resizable: false,

				items:[Ext.create('Ext.form.Panel', {
					border: false,
					method: 'POST',
					url: webapp.login.IDS.ACTION_URL,
					standardSubmit: true,

					items: [
						{
							xtype: 'textfield',
							name: webapp.login.IDS.FIELD_LOGIN.NAME,
							vtype:'email',
							fieldLabel: webapp.login.IDS.FIELD_LOGIN.LABEL
						},
						{
							xtype: 'textfield',
							name: webapp.login.IDS.FIELD_PASSWORD.NAME,
							fieldLabel: webapp.login.IDS.FIELD_PASSWORD.LABEL
						}, {
							xtype: 'checkbox',
							name: webapp.login.IDS.FIELD_REMEMBER_ME.NAME,
							fieldLabel: webapp.login.IDS.FIELD_REMEMBER_ME.LABEL
						}
					],
					buttons: [
						{
							text: 'Login',
							fromBind: true,
							handler: function() {
								var fp = this.ownerCt.ownerCt,
									form = fp.getForm();
								if(form.isValid()){
									form.submit();
								}
							}
						}
					]
				})]
			}).show();
		}
	};
})();
